package cn.dankal.flyaudio.personal

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import cn.dankal.basiclib.base.activity.BaseActivity
import cn.dankal.business.Constants.*
import cn.dankal.flyaudio.R
import cn.dankal.flyaudio.home.HomeFragment
import cn.dankal.flyaudio.home.MyActivityFragment
import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.activity_main.*

class MyActivityActivity : BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_my_activity
    }

    override fun initComponents() {
        mSectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager)
        // Set up the ViewPager with the sections adapter.
        container.adapter = mSectionsPagerAdapter
        container.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
        container.offscreenPageLimit = 3
        tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container))
        addSingleTitleBar("我的活动")
    }

    private var mSectionsPagerAdapter: SectionsPagerAdapter? = null


    inner class SectionsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {

        override fun getItem(position: Int): Fragment {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            when (position) {
                0 -> {
                    return MyActivityFragment.newInstance(TYPE_WAITING)
                }
                1 -> {
                    return MyActivityFragment.newInstance(TYPE_PROCESS)
                }
                2 -> {
                    return MyActivityFragment.newInstance(TYPE_FINISHED)
                }
            }
            return HomeFragment.newInstance()
        }

        override fun getCount(): Int {
            // Show 3 total pages.
            return 3
        }
    }
}
